package com.hfy.music.controller;

import com.hfy.model.dto.SheetDto;
import com.hfy.model.dto.ToSheetDto;
import com.hfy.music.service.SheetMusicService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import result.Result;

/**
 * @ author 韩
 * time: 2024/5/29 18:28
 */
@RestController
@RequestMapping("/sheet")
@Tag(name = "歌单控制器",description = "提供对歌单的各种操作接口")
public class SheetMusicController {

    @Autowired
    private SheetMusicService sheetMusicService;

    @GetMapping("/show/{account}")
    @Operation(summary = "展示用户的歌单")
    @Parameters(@Parameter(name = "account", description = "账号"))
    public Result showSheet(@PathVariable ("account") Long account) {
        return sheetMusicService.showSheet(account);
    }


    @GetMapping("/show_can_add")
    @Operation(summary = "展示用户的歌单")
    @Parameters({@Parameter(name = "account", description = "账号")
            ,@Parameter(name = "musicId", description = "音乐id")})
    public Result showCanAddSheet(@RequestParam ("musicId") Integer musicId,@RequestParam ("account") Long account) {
        return sheetMusicService.showCanAddSheet(account,musicId);
    }

    @PostMapping("/create")
    @Operation(summary = "创建一个新的歌单")
    @Parameters({@Parameter(name = "account", description = "账号"),
            @Parameter(name = "sheetName", description = "歌单名")})
    public Result createSheet(@RequestBody SheetDto dto) {

        return sheetMusicService.createSheet(dto.getAccount(), dto.getSheetName());
    }

    @PutMapping("/update")
    @Operation(summary = "修改歌单名称")
    @Parameters(@Parameter(name = "sheetName", description = "表名"))
    public Result updateSheet(@RequestBody String sheetName) {

        return sheetMusicService.updateSheet(sheetName);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除歌单")
    @Parameters(@Parameter(name = "sheetId", description = "歌单id"))
    public Result deleteSheet(@PathVariable("id") Integer sheetId) {
        return sheetMusicService.deleteSheet(sheetId);
    }

    @PostMapping("/add_music")
    @Operation(summary = "向歌单里添加音乐")
    @Parameters({@Parameter(name = "sheetId", description = "歌单id"),
            @Parameter(name = "musicId", description = "音乐id")})
    public Result addMusicToSheet(@RequestBody ToSheetDto dto) {
        return sheetMusicService.addMusicToSheet(dto.getSheetId(),dto.getMusicId());
    }

    @PostMapping("/delete_music")
    @Operation(summary = "在歌单里删除音乐")
    @Parameters({@Parameter(name = "sheetId", description = "歌单id"),
            @Parameter(name = "musicId", description = "音乐id")})
    public Result deleteMusicToSheet(@RequestBody ToSheetDto dto) {
        return sheetMusicService.deleteMusicToSheet(dto.getSheetId(),dto.getMusicId());
    }


}
